﻿using System.Collections.Generic;
using DotLiquid;
using Magnum.Linq;
using Wolfpack.Contrib.DashboardAdapter.Interfaces;
using Wolfpack.Core.Interfaces.Entities;

namespace Wolfpack.Contrib.DashboardAdapter.Formatters
{
    public class DotLiquidTemplateFormatter : IMessageFormatter
    {
        public string Format(string templateContent, NotificationEvent notification,
            IDictionary<string, object> additionalData = null)
        {
            var template = Template.Parse(templateContent);

            var values = notification.ToDictionary();

            if (additionalData != null)
            {
                foreach (var kvp in additionalData)
                    values[kvp.Key] = kvp.Value;
            }
            return template.Render(Hash.FromDictionary(values));
        }
    }
}